package com.leo.biz.controller;

import com.leo.biz.service.datacenter.CommServiceImpl;
import com.leo.biz.service.datakeep.DataCommKeeper;
import com.leo.biz.service.datakeep.FetchTaskManager;
import com.leo.biz.service.datakeep.FileReadServiceImpl;
import com.leo.biz.service.fetcher.BaseStockFetcher;

import com.leo.biz.service.impl.Alog;
import com.leo.biz.service.pub.DaoCenter;

import com.leo.biz.service.zookeeper.ZkTest;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

/**
 * Created by leo on 2016/1/29.
 */
@Controller
@RequestMapping(value = "/stock")
public class StockControllor {

    @Autowired
   private Alog alog;

    @Autowired
    @Qualifier("txStockFetcher")
    private BaseStockFetcher txStockFetcher;

    @Autowired
    private FileReadServiceImpl fileReadService;

    @Autowired
    private DaoCenter daoCenter;

    @Autowired
    private FetchTaskManager fetchTaskManager;

    @Autowired
    private  DataCommKeeper dataCommKeeper;

    @Autowired
    private CommServiceImpl commService;

    @Autowired
    private ZkTest zkTest;



    @RequestMapping(value="", method= RequestMethod.GET,produces = "application/json; charset=utf-8")
    public ModelAndView home(HttpSession session)
    {
          //(session.getServletContext().getRealPath("/"));
//        System.out.println(System.getProperty("user.dir"));

        ModelAndView modelAndView=new ModelAndView();
        WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
        Object tt=wac.getBean("propertyConfigurer");
        modelAndView.setViewName("stock/index");
        Subject currentUser = SecurityUtils.getSubject();

        modelAndView.addObject("username", currentUser.getPrincipal());
//        System.out.println(System.getProperty("os.name"));

//        alog=new Alog();
//        alog.setIsSupportConsole(true);
//        alog.setIsSupportFile(true);
//        alog.setMaxFileSize(20);
//        alog.debug("hello world");
      //  fileReadService.readDailyKRecord();
        return modelAndView;
    }

    @RequestMapping(value="/test", method= RequestMethod.GET,produces = "application/json; charset=utf-8")
    @ResponseBody
    public Object test(HttpSession session)
    {
       // RedisUtil.test();
        try {
            ZkTest.test();
        } catch (Exception e) {
            e.printStackTrace();
        }

//        return commService.getDayKAll("600595",20160701,201608020);
        return "OK";
    }


}

